﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.DataEntity;
using Cosmetic.Logic;
using DXBBS.Components;
using DXBBS.Business;
using DXBBS.Service;
using System.Reflection;
using System.Web.Caching;

/// <summary>
/// Summary description for BasePage
/// </summary>
public class PageBase2 : Page
{
    private UserManager m_UserManager = new UserManager();
    private RoleManager m_RoleManager = new RoleManager();
    private ForumManager m_ForumManager = new ForumManager();

    private User m_SignInUser;
    public User SignInUser1
    {
        get
        {
            if (null == this.m_SignInUser)
            {
                if (null != Session["SignInUser1"])
                {
                    this.m_SignInUser = Session["SignInUser1"] as User;
                }
            }
            return this.m_SignInUser;
        }
        set
        {
            Session["SignInUser1"] = value;
            this.m_SignInUser = value;
        }
    }

    public void SignOut()
    {
        //logout from bbs
        if (Sessions.UserID != 0)
        {
            Hashtable hashtable = (Hashtable)Caches.Read(CacheKey.OnlineList);
            if ((hashtable != null) && (hashtable[Sessions.UserID.ToString()] != null))
            {
                hashtable.Remove(Sessions.UserID.ToString());
            }
        }

        if (Cosmetic.WebGeneric.ReadBBSConfigInfo().Interface == 1)
        {
            try
            {
                ((IUser)Assembly.Load("DxbbsUserClass").CreateInstance("DxbbsUserClass.Interface")).outLogout(Sessions.UserName);
            }
            catch
            {
            }
        }
        Sessions.Abandon();
        Session.Abandon();
        Session.Remove("SignInUser1");
    }


    public bool CheckUserRole(RoleManager.ERole aRole)
    {
        if (null == this.SignInUser1)
        {
            return false;
        }
        return this.m_RoleManager.CheckUserRole(this.m_SignInUser.UserId, aRole);
    }

    public bool CheckForumAdmin(Guid aForumId)
    {
        if (null == this.SignInUser1)
        {
            return false;
        }
        return this.m_ForumManager.CheckForumAdmin(aForumId, this.SignInUser1.UserId);
    }
}
